﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System;
using CRM.Admin.Contracts.Contract.Customer;
using CRM.Admin.Contracts.Contract.Logs;
using CRM.Admin.Contracts.Dto.Customer;
using CRM.Admin.Contracts.Dto.Logs;
using CRM.Admin.Contracts.Model.Customer;
using CRM.Admin.Services.Service.Logs;
using KingsSharp.Common;
using KingsSharp.Common.Extensions;
using KingsSharp.Common.Filter;
using KingsSharp.Core.Data.Entity;
using KingsSharp.Core.Data.Extensions;
using KingsSharp.Web.Helper;
using KingsSharp.Web.UI;


namespace CRM.Admin.Areas.Customer.Controllers
{
    public class LinkManController : Controller
    {

        public ILinkManService LinkManService { get; set; }
        public ActionResult LinkManInsert()
        {
            return View();
        }
        #region 视图功能
        public ActionResult LinkManIndex()
        {
            return View();
        }

        /// <summary>
        /// 编辑页
        /// </summary>
        /// <param name="CompetitorId"></param>
        /// <returns></returns>
        public ActionResult LinkManEdit(Guid CustomerId)
        {
            var dto = LinkManService.LinkMans.Where(a => a.Id==CustomerId).FirstOrDefault().MapTo<LinkManDto>();
            return View(dto);
        }

        public ActionResult LinkManInsert(LinkManDto linkmanDto)
        {
            linkmanDto.CheckNotNull(nameof(linkmanDto));

            var result = LinkManService.Insert(linkmanDto);
            string msg = result.Message ?? result.ResultType.ToDescription();
            AjaxResultType msgType = result.ResultType.ToAjaxResultType();
            if (msgType != AjaxResultType.Error)
            {
                msg = "联系人“{0}”添加成功。".FormatWith(linkmanDto.Name);
            }
            return Json(new AjaxResult(msg, msgType));
        }
        public ActionResult LinkManUpdate(LinkManDto linkmanDto)
        {
            linkmanDto.CheckNotNull(nameof(linkmanDto));

            var result = LinkManService.Update(linkmanDto);
            string msg = result.Message ?? result.ResultType.ToDescription();
            AjaxResultType msgType = result.ResultType.ToAjaxResultType();
            if (msgType != AjaxResultType.Error)
            {
                msg = "联系人“{0}”更新成功。".FormatWith(linkmanDto.Name);
            }
            return Json(new AjaxResult(msg, msgType));
        }
        #endregion

    }
}